Jannah Theme License is not validated, Go to the theme options page to validate the license, You need a single license for each domain name.
Essentials

Three Of These Examples Have A list() Around Them. That Is The Lesson

Seventeen Python functions, three columns: the name, what it does, a worked example. It is a clean reference card and the examples are the part that makes it worth saving — most cheat sheets stop at the description.

Which is why it is worth noticing something the card does without comment. Look at rows nine, sixteen and seventeen:

list(range(1, 6))  ·  list(enumerate(['a', 'b']))  ·  list(zip([1, 2], ['a', 'b']))

Three of the seventeen examples have a list() wrapped around the thing being demonstrated. The other fourteen do not. The card never explains why — and that unexplained wrapper is the answer to the question almost every Python beginner asks in their first week.

They type print(range(1, 6)), expect to see the numbers one to five, and get back range(1, 6). It looks like the function failed. It did not. That is the whole lesson hiding inside this card’s punctuation, and it is worth more than fifteen of the seventeen definitions.

Four families, not seventeen names

SHOW AND ASK ASK ABOUT A VALUE CONVERT IT WORK ON SEQUENCES
print · input len · type int · float · str · list range · sum · max · min · sorted · abs · round · enumerate · zip
Talk to the person using the program Find out what you are holding Turn one kind of value into another Make, squash or reshape a series of things
Day one Day one Day one, because input always gives you text Week one onwards — this is where the work is
2 of 17 2 of 17 4 of 17 9 of 17
The card’s seventeen functions grouped by what they are for. The function names are the card’s own; the grouping is this blog’s — and the bottom row is the reason it is worth doing.

All seventeen, as the card lists them

Every word and every example below is the card’s own.

# Function What it does Example, as printed
1 print() Display output on the screen print("Hello, Python!")
2 input() Read input as a string name = input("Name: ")
3 len() Count items or characters len("Python") → 6
4 type() Return the data type of a value type(10) → <class 'int'>
5 int() Convert a value to an integer int("25") → 25
6 float() Convert a value to a float float("3.14") → 3.14
7 str() Convert a value to a string str(100) → “100”
8 list() Create a list from an iterable list("abc") → ['a', 'b', 'c']
9 range() Generate a range of numbers list(range(1, 6)) → [1, 2, 3, 4, 5]
10 sum() Sum all numbers in an iterable sum([1, 2, 3]) → 6
11 max() Return the largest item max([5, 2, 9]) → 9
12 min() Return the smallest item min([5, 2, 9]) → 2
13 sorted() Return a new sorted list sorted([3, 1, 2]) → [1, 2, 3]
14 abs() Return the absolute value abs(-10) → 10
15 round() Round a number, decimals optional round(3.786, 2) → 3.79
16 enumerate() Loop with index and value together list(enumerate(['a', 'b']))
17 zip() Combine iterables element by element list(zip([1, 2], ['a', 'b']))
All seventeen exactly as the card prints them. The three examples in bold are the ones wrapped in list() — the card does this without comment, and it is the most instructive thing on the whole card.

WATCH THE ORIGINAL — 20 SECONDS

All seventeen functions with their descriptions and worked examples, in one card.

▶ 17 essential Python functions — small functions, big impact — BANI Academy on Facebook

Why three of them need the wrapper

Most of the functions on this card hand you a finished thing. len gives you a number. sorted gives you a new list. str gives you text. You can print any of them and see the answer.

Three of them do not. range, enumerate and zip hand you a recipe rather than a result — an object that knows how to produce values one at a time, when something asks for them. Nothing has been calculated yet.

That is why printing one looks broken. There is nothing to show; the values have not been made. And it is why wrapping it in list() fixes it instantly: list is the thing that says go on then, produce them all now.

It also explains the thing beginners find most confusing about this — a loop works perfectly without the wrapper. Writing for i in range(1, 6): needs no list(), because the loop asks for one value at a time, which is exactly what the recipe is good at. So the same expression appears broken in one place and works fine in another, three lines apart.

Why would the language do this? Because a recipe costs nothing to hold. range(1, 1000000) occupies almost no memory until something starts asking. A finished list of a million numbers does not. For a beginner the behaviour is a nuisance; at any real scale it is the reason your program does not fall over.

So: add list() when you want to look at it. Leave it off when you want to loop over it. That is the entire rule, and the card has been demonstrating it in silence the whole time.

The nine sequence functions, sorted by what they give back

Function What it does to a sequence What you get back Needs list() to see it?
range Makes a sequence A recipe for numbers Yes, to look at it
enumerate Reshapes a sequence A recipe of index-and-value pairs Yes, to look at it
zip Reshapes two sequences A recipe of paired-up items Yes, to look at it
sorted Reshapes a sequence A brand new list — the original is untouched No
sum Squashes a sequence One number No
max Squashes a sequence One item No
min Squashes a sequence One item No
abs Works on one number One number No
round Works on one number One number No
The nine sequence functions from the card, split by whether they hand you a result or a recipe. This whole table is this blog’s addition.

Four honest caveats

Rows two and five sit together for a reason. The card says input() reads input as a string, and that word is doing a lot of work. Ask somebody for their age and you get the text “25”, not the number 25 — which is why the conversion functions are the very next block on the card. The classic beginner bug is adding two numbers and getting “2525” instead of 50. The card’s ordering is quietly teaching the fix.

Rounding is not as simple as row fifteen looks. The example is honest and correct, but numbers with decimals are stored approximately on every computer, so a few cases round in the direction you did not expect. It bites people doing money calculations. For anything financial, do not reach for this function — use a type built for exact decimals.

A reference is not a curriculum. Seventeen functions on one card is a thing to keep beside you, not a syllabus to work through. You will learn five of them properly in the first week of an actual project and meet the rest when you need them, which is the argument we made for going narrow in Pick One Per Stage And Learn It Properly.

These are the language’s own functions, not ones you write. Worth saying because “Python functions” means two different things in the first fortnight — the built-in tools listed here, and the functions you define yourself with def. This card is the first kind. The second kind is where the actual programming starts.

Questions people ask

Why does my loop work but my print not? Because the loop asks for one value at a time and the print asks to see everything at once. Same expression, two different demands.

Can I always just add list() to be safe? You can, and nothing breaks for small data. Do not do it on something huge, and never on something endless — that is the one case where the wrapper turns a working program into a frozen one.

Which five should I actually learn first? print, input, len, range and int. With those five and a loop you can write something that asks a question, counts, and answers. Everything else on the card is a convenience you will meet when a project needs it.

Where should I learn the rest? From a project, not a list. If you want a channel to learn alongside, the Python row on the card we covered in Nineteen Of These Channels Own One Word is a reasonable starting point — and the reason to start from the thing you want to build rather than the language is in Which Language Should I Learn First Is The Wrong Question.

The punctuation was the lesson

Seventeen functions, seventeen one-line descriptions, seventeen examples. Fourteen of the examples show you a result. Three show you a result and a wrapper, and the wrapper is there because those three do something fundamentally different from the rest.

Nobody labelled it. It is just sitting in the syntax, in three rows out of seventeen, waiting for somebody to ask why those three look different. That question is worth more than memorising the other fourteen — and it is the habit worth taking from every reference card you ever save: when one row is punctuated differently, that is where the actual information is.

Learning a lot does not make anyone good. Doing a lot does.

If you want a deadline rather than a saved cheat sheet, we run a free challenge — there is no barrier to entry, only a commitment fee that is refunded when you finish. It exists because a deadline makes you write the loop, and a reference card only describes it.

Which of the seventeen did you misunderstand longest? Tell us in the comments under the original reel.

More on building a channel for a global audience at mmoyoutube.com.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button